// Copyright 2025 CCC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import webSee from '@websee/core';
import performance from '@websee/performance';
import recordscreen from '@websee/recordscreen';

export class WebSee {
  constructor(userId: string) {
    if (import.meta.env.VITE_MODE === 'production') {
      this.init(userId);
    }
  }
  init(userId: string) {
    webSee.init({
      dsn: `${import.meta.env.VITE_MONITOR_URL}/v1/mgb/monitor`,
      apikey: import.meta.env.VITE_APP_NAME,
      userId,
      handleHttpStatus(data) {
        const { response } = data;
        const { code } = typeof response === 'string' ? JSON.parse(response) : response;

        return code === 200;
      },
    });
    webSee.use(performance, {});
    webSee.use(recordscreen, {});
  }

  public static Log(params: Record<string, any>) {
    if (import.meta.env.VITE_MODE === 'production') {
      webSee.log(params);
    }
  }
}
